package cn.xxxy.fourm.dao;

import java.util.Collection;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.xxxy.fourm.entity.User;

public interface UserDao extends JpaRepository<User, Integer>{
	List<User> findByEmail(String email);
	List<User> findByEmailOrUpass(String email,String upass);
	User findByEmailAndUname(String email,String Uname);
	//@Query(from User where x.startDate between ?1 and ?2)
	//List<User> findByCreateTimeBetween(String date1,String date2);
	//List<User> findByAgeLessThan(int age);
	//List<User> findByUserNameLike(String username);
	//List<User> findByUserNameStartingWith(String xx);
	//List<User> findByUserNameIgnoreCase(String username);
	
	/*@Query("select u.userName,u.id,u.email,u.nickName,u.startTime,m.birthday from User u inner join u.message m")
	List<Object[]> getUserMessage();
	
	@Query("select u.userName,u.id,u.email,u.nickName,u.startTime,o.oid,o.ordertime,o.totalprice from User u inner join u.orders o")
	List<Object[]> listUserOrder();*/
	@Query("select u.uname,u.uid,u.email,u.phone,s.sid,s.sname,r.rid,r.rname from User u inner join u.userState s inner join u.userRole r")
	Collection<User> listUsers();
	/**
	 * �û���¼
	 * @return
	 */
	@Query("from User where uname=?1 and upass=?2 and sid=1")
	User login(String uname,String upass);
	/**
	 * 修改用户基本信息
	 * @param email
	 * @param phone
	 * @param address
	 * @param sign
	 * @param uid
	 */
	@Modifying(clearAutomatically=true)
    @Transactional
	@Query("update User set email=?1, phone=?2,address=?3,sign=?4 where uid=?5 ") 
	void updateEmailAndPhoneAndAddressAndSign(String email, String phone, String address, String sign,Integer uid);
}
